//
//  ARPlayerControl.m
//  AriseSamePro
//
//  Created by 包日守 on 15/10/30.
//  Copyright © 2015年 Arise. All rights reserved.
//

#import "ARPlayerControl.h"
#import "ARAudioPlayDefault.h"

@interface ARPlayerControl ()



@property (weak, nonatomic) IBOutlet UILabel *titlelabel;
@property (weak, nonatomic) IBOutlet UIImageView *playDot;



@property (weak, nonatomic) IBOutlet UIButton *InButton;


@end



@implementation ARPlayerControl

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (IBAction)playbuttonClick:(id)sender {
    
    ARAudioPlayDefault * audioDefault = [ARAudioPlayDefault defaultAudioPlay];
    if (![audioDefault.title isEqualToString:audioDefault.playingCate.mediaModel.musicModel.title]) {
        return;
    }
    
    
    UIButton *button = (UIButton *)sender;
    button.selected = !button.selected;

    
    if (button.selected) {
       [audioDefault startMusic];
    }
    else
    {
        [audioDefault pauseMusic];
    }
    
    if (self.refleshTableView) {
        [self.refleshTableView reloadData];
    }
    
    
    
    
    
}

- (void) viewRefrash
{
    ARAudioPlayDefault * audioDefault = [ARAudioPlayDefault defaultAudioPlay];
    
    self.titlelabel.text = [NSString stringWithFormat:@"%@ - %@",audioDefault.title,audioDefault.author];
    
    self.progressVeiw.progress = (float)audioDefault.player.currentTime/audioDefault.duration.floatValue;
    self.playDotConstraint.constant = 14+ self.progressVeiw.progress * 320;
    
    self.playButton.selected = NO;
    

}



- (void) viewCreate
{
    ARAudioPlayDefault * audioDefault = [ARAudioPlayDefault defaultAudioPlay];
    
    self.titlelabel.text = [NSString stringWithFormat:@"%@ - %@",audioDefault.title,audioDefault.author];
        //self.progressVeiw.progress = 0;
        //self.playDotConstraint.constant = 13;


}

- (void) awakeFromNib
{
    
    
    [self.playButton setImage:[UIImage imageNamed:@"pause_button@2x"] forState:UIControlStateSelected];
    self.playButton.selected = YES;
    
    ARAudioPlayDefault * audioDefault = [ARAudioPlayDefault defaultAudioPlay];
    
    //audioDefault.player.currentTime
    
    //[audioDefault.player addObserver:self forKeyPath:@"currentTime" options:NSKeyValueObservingOptionOld|NSKeyValueObservingOptionNew context:nil];
    
    

}
/*
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    float progress = [[object valueForKeyPath:keyPath] floatValue];
    self.progressVeiw.progress = progress;
    self.playDotConstraint.constant = 14+ self.progressVeiw.progress * 320;
    
}
*/

@end
